﻿'' ------------------------------------------------------
'' TabManager
''    is a collection of useful functions that use
''    for retrieving and modifying tab control
'' ------------------------------------------------------

Imports GrayIris.Utilities.UI.Controls

Public Class TabManager
    Private Tabs As YaTabControl

    Public Sub New(ByVal pTabs As YaTabControl)
        Tabs = pTabs
    End Sub

    ''' <summary>
    ''' Check whether selected tab is editor tab
    ''' </summary>
    ''' <returns>True if selected tab is editor form</returns>
    Public Function IsSelectedTabEditor() As Boolean
        Return Tabs.SelectedTab.Tag.GetType Is GetType(frmEditor)
    End Function

    ''' <summary>
    ''' Check whether a tab is editor tab
    ''' </summary>
    ''' <param name="index">Tab index</param>
    ''' <returns>True if a tab is editor form</returns>
    Public Function IsEditorAt(ByVal index As Integer) As Boolean
        Return Tabs.Controls(index).Tag.GetType Is GetType(frmEditor)
    End Function

    Public Function IsEditor(ByVal page As YaTabPage) As Boolean
        Return page.Tag.GetType Is GetType(frmEditor)
    End Function

    Public Function GetSelectedEditor() As frmEditor
        If IsSelectedTabEditor() Then
            Return CType(Tabs.SelectedTab.Tag, frmEditor)
        Else
            Return Nothing
        End If
    End Function

    Public Function GetEditorAt(ByVal index As Integer) As frmEditor
        If IsEditorAt(index) Then
            Return CType(Tabs.Controls(index).Tag, frmEditor)
        Else
            Return Nothing
        End If
    End Function
End Class
